#ifndef SIMPLE_SENSOR_H
#define SIMPLE_SENSOR_H
#include "stdint.h"
typedef uint32_t (*SensorAngle)(void);
typedef int      (*SensorFullRotations)(void);
typedef double   (*PreciseAngle)(void);
typedef float    (*Angle)(void);
/**
 *  Direction structure
 */
typedef enum Direction {
    Direction_CW      = 1,  // clockwise
    Direction_CCW     = -1, // counter clockwise
    Direction_UNKNOWN = 0   // not yet known or invalid state
}Direction;


typedef struct 
{
    // velocity calculation variables
    float velocity;
    float angle_prev; // result of last call to getSensorAngle(), used for full rotations and velocity
    long angle_prev_ts; // timestamp of last call to getAngle, used for velocity
    float vel_angle_prev; // angle at last call to getVelocity, used for velocity
    long vel_angle_prev_ts; // last velocity calculation timestamp
    int32_t full_rotations; // full rotation tracking
    int32_t vel_full_rotations; // previous full rotation value for velocity calculation
}SensorState_t;

typedef struct
{
	Angle                        getSensorAngle;
  SensorFullRotations          getFullRotations;     //旋转圈数
  PreciseAngle                 getPreciseAngle;      //精确角度
  Angle                        getAngle;             //角度
  Angle                        getMechanicalAngle;   //机械角度
	Angle                        getVelocity;          //速度
}SimpleSensorFunction_t;
typedef struct
{
    float                        min_elapsed_time;     // default is 100 microseconds, or 10kHz
	  SimpleSensorFunction_t       function;             //
    SensorState_t                state;
}SimpleSensor_t;

void Simple_Sensor_update(SimpleSensor_t *handle);
float Simple_Sensor_getVelocity(SimpleSensor_t *handle);
float Simple_Sensor_getMechanicalAngle(SimpleSensor_t *handle);
float Simple_Sensor_getAngle(SimpleSensor_t *handle);
double Simple_Sensor_getPreciseAngle(SimpleSensor_t *handle);
int32_t Simple_Sensor_getFullRotations(SimpleSensor_t *handle);
int Simple_Sensor_needsSearch(SimpleSensor_t *handle);  //

void Simple_Sensor_init(SimpleSensor_t *handle);
void SimpleSensor_FunctionRegister(SimpleSensor_t *handle,SimpleSensorFunction_t f);
#endif
